﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DAO;

namespace TAM_SPORT
{
    public partial class GetAndPayments : TAM_SPORT.FormBase
    {
        private PaymentDao pay;
        public GetAndPayments()
        {
            InitializeComponent();
            pay = new PaymentDao();
            loadGrig();
        }
        private void loadGrig()
        {
            double total = 0;
            double debit = 0;
            double paymet = 0;
            dtgCustomers.Rows.Clear();
            DataTable table = pay.getGetAndPayment(dtFromDate.Value, dtpToDate.Value);
            if (table != null && table.Rows.Count > 0)
            {
                foreach (DataRow row1 in table.Rows)
                {
                    int i = dtgCustomers.Rows.Add();
                    dtgCustomers.Rows[i].Cells[0].Value = i + 1;
                    total += double.Parse(row1["MONEY_GET"].ToString()) + double.Parse(row1["SALE_MONEY"].ToString());
                    debit += double.Parse(row1["DEBIT_MONEY"].ToString());
                    paymet += double.Parse(row1["MONEY_PAY"].ToString());
                    dtgCustomers.Rows[i].Cells[1].Value = row1["PURCHASE_DATE"].GetType().FullName == "System.DBNull" ? "" : DateTime.Parse(row1["PURCHASE_DATE"].ToString()).ToString("dd/MM/yyyy");
                    dtgCustomers.Rows[i].Cells[2].Value = row1["MONEY_GET"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["MONEY_GET"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[3].Value = row1["SALE_PAY_MONEY"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["SALE_PAY_MONEY"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[4].Value = row1["DEBIT_MONEY"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["DEBIT_MONEY"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[5].Value = row1["MONEY_PAY"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["MONEY_PAY"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[6].Value = row1["IMPORT_VALUE"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["IMPORT_VALUE"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[7].Value = row1["AMOUNT"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["AMOUNT"].ToString()).ToString("#,###");
                    dtgCustomers.Rows[i].Cells[8].Value = row1["CASH"].GetType().FullName == "System.DBNull" ? "0" : float.Parse(row1["CASH"].ToString()).ToString("#,###");
                    if (i % 2 == 1)
                    {
                        dtgCustomers.Rows[i].DefaultCellStyle.BackColor = Color.LightCyan;
                    }
                }
            }
            lblThu.Text = total.ToString("#,###.##");
            lblTongSoTienChi.Text = paymet.ToString("#,###.##");
            lblDeblt.Text = debit.ToString("#,###.##");
            lblDanhThu.Text =(total-debit-paymet).ToString("#,###.##");
        }
        private void btnView_Click(object sender, EventArgs e)
        {
            loadGrig();
        }
    }
}
